package com.kisyou.blogs;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

// Util: 工具
// 因为这一段代码会重复写
public class DBUtil {
    private static final DataSource dataSource;

    static {
        MysqlDataSource mysqlDataSource = new MysqlDataSource();

        mysqlDataSource.setUser("debian-sys-maint");
        mysqlDataSource.setPassword("co7lI761pHOFy9gx");
        mysqlDataSource.setUrl("jdbc:mysql://127.0.0.1:3307/jdbc_mysql?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai");
        dataSource = mysqlDataSource;
    }

    public static Connection connection() throws SQLException {
        return dataSource.getConnection();
    }
}